package com.yida.gwj.basis.service.impl;

import com.yida.common.core.utils.DateUtils;
import com.yida.common.security.utils.SecurityUtils;
import com.yida.gwj.basis.domain.GwjInitBusinessOwner;
import com.yida.gwj.basis.mapper.GwjInitBusinessOwnerMapper;
import com.yida.gwj.basis.service.IGwjInitBusinessOwnerService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 业务业主信息（基础数据管理模块）Service业务层处理
 *
 * @author lqq
 * @date 2022-11-15
 */
@Service
public class GwjInitBusinessOwnerServiceImpl implements IGwjInitBusinessOwnerService {

	@Resource
	private GwjInitBusinessOwnerMapper businessOwnerMapper;

	/**
	 * 获取业务业主集合
	 *
	 * @param businessOwner 业务业主信息（基础数据管理模块）
	 * @return /
	 */
	@Override
	public List<GwjInitBusinessOwner> getList(GwjInitBusinessOwner businessOwner) {
		return businessOwnerMapper.selectList(businessOwner);
	}

	/**
	 * 获取业务业主集合
	 *
	 * @param houseCodes 房屋标识码集合
	 * @param bizId      业务ID
	 * @return /
	 */
	@Override
	public List<GwjInitBusinessOwner> getList(String[] houseCodes, Long bizId) {
		return businessOwnerMapper.selectListInCode(houseCodes, bizId);
	}

	/**
	 * 新增业务业主信息（基础数据管理模块）
	 *
	 * @param businessOwner 业务业主信息（基础数据管理模块）
	 * @return 结果
	 */
	@Override
	public int save(GwjInitBusinessOwner businessOwner) {
		businessOwner.setCreateBy(SecurityUtils.getLoginUser().getSysUser().getRealName());
		businessOwner.setCreateTime(DateUtils.getNowDate());
		return businessOwnerMapper.insert(businessOwner);
	}

	/**
	 * 批量新增业务业主信息（基础数据管理模块）
	 *
	 * @param businessOwners 业务业主信息（基础数据管理模块）
	 * @return 结果
	 */
	@Override
	public int saveBatch(List<GwjInitBusinessOwner> businessOwners) {
		return businessOwnerMapper.insertBatch(businessOwners);
	}

	/**
	 * 修改业务业主信息（基础数据管理模块）
	 *
	 * @param businessOwner 业务业主信息（基础数据管理模块）
	 * @return 结果
	 */
	@Override
	public int updateById(GwjInitBusinessOwner businessOwner) {
		businessOwner.setUpdateBy(SecurityUtils.getLoginUser().getSysUser().getRealName());
		businessOwner.setUpdateTime(DateUtils.getNowDate());
		return businessOwnerMapper.updateById(businessOwner);
	}

	/**
	 * 修改业务业主信息（基础数据管理模块）
	 *
	 * @param businessOwners 业务业主信息（基础数据管理模块）
	 * @return 结果
	 */
	@Override
	public int updateBatch(List<GwjInitBusinessOwner> businessOwners) {
		return businessOwnerMapper.updateBatch(businessOwners);
	}

	/**
	 * 根据房屋标识码获取业主信息
	 *
	 * @param houseCode 房屋标识码
	 * @param bizId    地区ID
	 * @return /
	 */
	@Override
	public GwjInitBusinessOwner getByHouseCode(String houseCode, Long bizId) {
		GwjInitBusinessOwner businessOwner = new GwjInitBusinessOwner();
		businessOwner.setBizId(bizId);
		businessOwner.setHouseCode(houseCode);
		return businessOwnerMapper.selectOne(businessOwner);
	}

	/**
	 * 根据业务ID获取业主信息
	 *
	 * @param bizId 业务ID
	 * @return /
	 */
	@Override
	public List<GwjInitBusinessOwner> getListByBizId(Long bizId) {
		GwjInitBusinessOwner businessOwner = new GwjInitBusinessOwner();
		businessOwner.setBizId(bizId);
		return businessOwnerMapper.selectList(businessOwner);
	}

	/**
	 * 根据房屋标识码删除业主
	 *
	 * @param houseCodes 房屋标识码
	 * @param bizId     业务ID
	 * @return /
	 */
	@Override
	public int deleteByHouseCodesAndBizId(List<String> houseCodes, Long bizId) {
		return businessOwnerMapper.deleteByHouseCodesAndBizId(houseCodes, bizId);
	}

	/**
	 * 根据业务ID删除业主
	 *
	 * @param bizId 业务ID
	 * @return /
	 */
	@Override
	public int deleteByBizId(Long bizId) {
		return businessOwnerMapper.deleteByBizId(bizId);
	}

	/**
	 * 根据房屋编号查询业主信息
	 * @param houseCode 房屋编号
	 * @param areaId  区域主键
	 * @return
	 */
	@Override
	public List<GwjInitBusinessOwner>  ownerInfoByHouseCode(String houseCode,Long areaId) {
		GwjInitBusinessOwner owner = new GwjInitBusinessOwner();
		owner.setHouseCode(houseCode);
		owner.setAreaId(areaId);
		return businessOwnerMapper.selectList(owner);
	}
}
